package GreedyAlgorithmPackage;

import org.junit.jupiter.api.Test;

/**
 * @author Lzm
 * @version 1.0
 */
public class jump_ {

  @Test
  public void jumpTest(){
    int[] nums = new int[]{2,3,1,1,4};
    System.out.println(jump(nums));
  }

  /*还是范围覆盖*/
  public int jump(int[] nums) {
    if (nums.length == 1){
      return 0;
    }
    int result = 0;
    /*记录当前nums[i]的覆盖范围*/
    int cover = 0;
    /*记录下一步的覆盖范围*/
    int nextCover = 0;

    for (int i = 0 ; i < nums.length ; i++){
      nextCover = Math.max(nextCover,nums[i] + i);
      if (i == cover){
        if (cover != nums.length - 1){
          cover = nextCover;
          result++;
        }
      }
    }
    return result;
  }
}
